from pydantic import BaseModel
from typing import Optional
from datetime import datetime
from uuid import UUID


class LLMProviderCreate(BaseModel):
    code: str
    name: str
    base_url: Optional[str] = None
    auth_type: str
    enabled: bool = True


class LLMProviderUpdate(BaseModel):
    name: Optional[str] = None
    base_url: Optional[str] = None
    auth_type: Optional[str] = None
    enabled: Optional[bool] = None


class LLMProviderRead(BaseModel):
    id: UUID
    code: str
    name: str
    base_url: Optional[str] = None
    auth_type: str
    enabled: bool

    class Config:
        from_attributes = True


class LLMModelCreate(BaseModel):
    provider_id: str
    code: str
    display_name: str
    context_window: Optional[int] = None
    max_output_tokens: Optional[int] = None
    default_temperature: Optional[float] = None
    endpoint_path: Optional[str] = None
    extra_headers_json: Optional[str] = None
    enabled: bool = True


class LLMModelUpdate(BaseModel):
    code: Optional[str] = None
    display_name: Optional[str] = None
    context_window: Optional[int] = None
    max_output_tokens: Optional[int] = None
    default_temperature: Optional[float] = None
    endpoint_path: Optional[str] = None
    extra_headers_json: Optional[str] = None
    enabled: Optional[bool] = None


class LLMModelRead(BaseModel):
    id: UUID
    provider_id: UUID
    code: str
    display_name: str
    context_window: Optional[int] = None
    max_output_tokens: Optional[int] = None
    default_temperature: Optional[float] = None
    endpoint_path: Optional[str] = None
    extra_headers_json: Optional[str] = None
    enabled: bool

    class Config:
        from_attributes = True


class LLMSecretCreate(BaseModel):
    provider_id: str
    name: str
    secret_value: str
    enabled: bool = True


class LLMSecretUpdate(BaseModel):
    provider_id: Optional[str] = None
    name: Optional[str] = None
    secret_value: Optional[str] = None
    enabled: Optional[bool] = None


class LLMSecretRead(BaseModel):
    id: UUID
    provider_id: UUID
    name: str
    cipher_algo: str
    key_id: str
    rotation_version: int
    enabled: bool
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True